﻿using System;
using System.Windows.Input;
using Foundation;

namespace Poet.ViewModels
{
    /// <summary>
    /// Base Main View Model.
    /// </summary>
    public abstract class BaseMainViewModel : ViewModel
    {
        protected BaseMainViewModel()
        {
            ShowMainMenu = true;
            CheckAllToolBarsCommand = new RoutedCommand();
            CommandBindings.Add(new CommandBinding(CheckAllToolBarsCommand, OnExecute, OnCanExecute));
        }

        private void OnCanExecute(object o, CanExecuteRoutedEventArgs args)
        {
            if (bool.Parse((string) args.Parameter))
                args.CanExecute = !(ShowStandartToolBar && ShowFormatToolBar && ShowHighlightToolBar);
            else args.CanExecute = ShowStandartToolBar || ShowFormatToolBar || ShowHighlightToolBar;
        }

        private void OnExecute(object o, ExecutedRoutedEventArgs args)
        {
            ShowStandartToolBar = ShowFormatToolBar = ShowHighlightToolBar = bool.Parse((string)args.Parameter);
        }

        public ICommand New { get; set; }

        public ICommand Open { get; set; }

        public ICommand Exit { get; set; }

        public ICommand About { get; set; }

        public ICommand CheckAllToolBarsCommand { get; set; }


        public bool ShowMainMenu
        {
            get { return Get(() => ShowMainMenu); }
            set { Set(() => ShowMainMenu, value); }
        }

        public bool ShowStandartToolBar
        {
            get { return Get(() => ShowStandartToolBar); }
            set { Set(() => ShowStandartToolBar, value); }
        }

        public bool ShowFormatToolBar
        {
            get { return Get(() => ShowFormatToolBar); }
            set { Set(() => ShowFormatToolBar, value); }
        }

        public bool ShowHighlightToolBar
        {
            get { return Get(() => ShowHighlightToolBar); }
            set { Set(() => ShowHighlightToolBar, value); }
        }

        public bool ShowStatusBar
        {
            get { return Get(() => ShowStatusBar); }
            set { Set(() => ShowStatusBar, value); }
        }
    }
}
